package com.jie.langlangmall.controller;

import com.jie.langlangmall.common.api.CommonPage;
import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.dto.PmsBrandParam;
import com.jie.langlangmall.model.PmsBrand;
import com.jie.langlangmall.service.PmsBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/22
 * @Email 3217998214@qq.com
 * @Description 商品品牌管理
 */
@RestController
@Tag(name = "PmsBrandController", description = "商品品牌管理")
@RequestMapping("/brand")
public class PmsBrandController {

    @Autowired
    private PmsBrandService brandService;

    @Operation(summary = "分页查询品牌")
    @GetMapping("/list")
    public CommonResult<CommonPage<PmsBrand>> getList(@RequestParam(value = "keyword", required = false) String keyword,
                                                      @RequestParam(value = "showStatus", required = false) Integer showStatus,
                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        List<PmsBrand> brandList = brandService.list(keyword, showStatus, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(brandList));
    }

    @Operation(summary = "获取全部品牌列表")
    @GetMapping("/listAll")
    public CommonResult<List<PmsBrand>> listAll() {
        return CommonResult.success(brandService.listAll());
    }

    @Operation(summary = "添加新的品牌")
    @PostMapping("/create")
    public CommonResult<Object> create(@Validated @RequestBody PmsBrandParam brandParam) {
        brandService.create(brandParam);
        return CommonResult.success();
    }

    @Operation(summary = "更新品牌")
    @PostMapping("/update/{id}")
    public CommonResult<?> update(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandParam brandParam) {
        brandService.update(id, brandParam);
        return CommonResult.success();
    }

    @Operation(summary = "删除品牌")
    @GetMapping("/delete/{id}")
    public CommonResult<?> delete(@PathVariable("id") Long id) {
        brandService.delete(id);
        return CommonResult.success();
    }

    @Operation(summary = "批量删除品牌")
    @PostMapping("/delete/batch")
    public CommonResult<?> deleteBatch(@RequestParam("ids") List<Long> ids) {
        brandService.deleteBatch(ids);
        return CommonResult.success();
    }

    @Operation(summary = "批量更新显示状态")
    @PostMapping("/update/showStatus")
    public CommonResult<?> updateShowStatus(@RequestParam("ids") List<Long> ids,
                                            @RequestParam("showStatus") Integer showStatus) {
        brandService.updateShowStatus(ids, showStatus);
        return CommonResult.success();
    }

    @Operation(summary = "批量更新厂家制造商状态")
    @PostMapping("/update/factoryStatus")
    public CommonResult<?> updateFactoryStatus(@RequestParam("ids") List<Long> ids,
                                               @RequestParam("factoryStatus") Integer factoryStatus) {
        brandService.updateFactoryStatus(ids, factoryStatus);
        return CommonResult.success();
    }

    @Operation(summary = "根据ID获取品牌信息")
    @GetMapping("/{id}")
    public CommonResult<PmsBrand> getItem(@PathVariable("id") Long id) {
        return CommonResult.success(brandService.getItem(id));
    }
}
